import util.TreeNode;

/**
 * Created by loso on 2017/3/17.
 */
public class _111_MinimumDepthOfBinaryTree {


    //因为左右的里面如果有一个是叶子节点的话，就返回他们的和，反正有一个是0；
    public int minDepthBigboss(TreeNode root) {
        if(root == null) return 0;
        int left = minDepth(root.left);
        int right = minDepth(root.right);
        return (left == 0 || right == 0) ? left + right + 1: Math.min(left,right) + 1;

    }

    public int minDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return findDepth(root);
    }

    public int findDepth(TreeNode root) {
        if (root.left == null && root.right == null) {
            return 1;
        }
        if (root.left == null) {
            return minDepth(root.right)+1;
        }
        if (root.right == null) {
            return minDepth(root.left)+1;
        }
        return Math.min(minDepth(root.left)+1,minDepth(root.right)+1);
    }
}
